package com.hmz.backend.api;

import lombok.Data;

@Data
public class ResultData<T> {
    private int status; //返回状态码
    private String message; //返回信息
    private T data; //返回数据
    private long timestamp; //返回时间戳
    public ResultData(){
        this.timestamp = System.currentTimeMillis(); //获取当前时间戳
    }
    //成功格式封装
    public static <T> ResultData<T> success (T data){
        ResultData<T> resultData = new ResultData<>();
        resultData.setStatus(ReturnCode.RC200.getCode());
        resultData.setMessage(ReturnCode.RC200.getMessage());
        resultData.setData(data);
        return resultData;
    }
    //失败格式封装
    public static <T> ResultData<T> fail(int code,String message){
        ResultData<T> resultData = new ResultData<>();
        resultData.setStatus(code);
        resultData.setMessage(message);
        return resultData;
    }

}
